home *** CD-ROM | disk | FTP | other *** search
- /*
- GETKEY( void )
-
- This function can be used as a direct replacement for the getch()
- function in the Microsoft C and QuickC runtime libraries.
-
- The original Microsoft functions did not properly report ALT-Q
- or ALT-R combinations, but instead activated their respective
- DOS functions of 'printer redirection' and 'pause'.
-
- GETKEY() functions exactly like the getch() function in that
- it must be called twice to retrieve extended keycodes.
-
- Any suggestions are welcomed. Please send to CIS 72520,3710
-
-
- Copyright (c) 1991 RWR Consulting
- ALL RIGHTS RESERVED
-
- Placed in the public domain October, 1991
-
- May be freely distributed.
-
-
- */
-
-
- /* INCLUDE FILES REQUIRED: bios.h ctype.h */
-
-
-
- int getkey( void )
- {
-
- /* Static vars are used to eliminate redundant memory peeks
- and constant setting of _KEYBRD values */
-
-
- /* Additionally, to function as getch() does, the scan code
- must be preserved and flagged for subsequent calls */
-
-
- unsigned key, scan, ascii;
-
- static int kread = _KEYBRD_READ;
- static int kready = _KEYBRD_READY;
- static int kshiftstatus = _KEYBRD_SHIFTSTATUS;
-
- static int initflag = 1;
- static int extended = 0;
- static unsigned int nextkey = 0;
-
-
-
- /* If bit 4 (& 0x10) of byte at 0x0040:0x0096 is set (See Norton),
- a new keyboard is present. */
-
-
- if(initflag) /* only do it once */
- {
- if( (*(unsigned char _far *)0x00400096 ) & 0x10 )
- {
-
- /* Setup for enhanced (new) keyboards */
-
- kread = _NKEYBRD_READ;
- kready = _NKEYBRD_READY;
- kshiftstatus = _NKEYBRD_SHIFTSTATUS;
- }
-
- initflag = 0; /* and never again */
- }
-
-
-
- /* If an extended code (see below), return the extended portion
- and reset the flag */
-
- if(extended)
- {
- extended = 0;
- return((int)nextkey);
- }
-
-
- key = _bios_keybrd( kread );
-
- /* Split return value into the scan and ascii codes. */
-
- scan = key >> 8;
- ascii = key & 0x00ff;
-
-
- /* Determine if the key was an extended one */
-
- if( (ascii == 0) || (ascii == 0xE0 ) )
- {
- /* If so, set the flag and return the 0x00 or 0xE0 to
- the calling function and save the second half for later */
-
- extended = 1;
- nextkey = scan;
- }
- else
- {
- /* Otherwise, just reset the flag */
-
- extended = 0;
- }
-
-
- /* Return the first code; may be 0x00 or 0xE0 if extended */
-
- return((int)ascii);
-
- }
-
-
-